<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="日期" prop="rq">
        <el-date-picker clearable
          v-model="queryParams.rq"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['kws:data:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['kws:data:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['kws:data:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['kws:data:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
        <!--      <el-table-column label="主键" align="center" prop="id" />-->
      <el-table-column prop="" label="序号" align="center" width="80">
        <template slot-scope="scope">
          {{scope.$index+1 +(queryParams.pageNum-1)*queryParams.pageSize}}
        </template>
      </el-table-column>

      <el-table-column label="日期" align="center" prop="rq" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.rq, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="天气" align="center" prop="tq" width="80"/>
      <el-table-column label="游客量" align="center" prop="tourists" />
<!--      <el-table-column label="刷卡" align="center" prop="swipe" />-->
<!--      <el-table-column label="买票" align="center" prop="buyTickets" />-->
<!--      <el-table-column label="免票" align="center" prop="freeTicket" />-->
      <el-table-column label="综合营收" align="center" prop="multiplePurpose" />
      <el-table-column label="门票" align="center" prop="gateMoney" />
<!--      <el-table-column label="线上" align="center" prop="online" />-->
<!--      <el-table-column label="成人" align="center" prop="onlineAdult" />-->
<!--      <el-table-column label="儿童" align="center" prop="onlineChildren" />-->
<!--      <el-table-column label="双人" align="center" prop="onlineDouble" />-->
<!--      <el-table-column label="一大一小" align="center" prop="onlineBigSmall" />-->
<!--      <el-table-column label="两大一小" align="center" prop="onlineTwoBigSmall" />-->
<!--      <el-table-column label="线下" align="center" prop="offline" />-->
<!--      <el-table-column label="成人" align="center" prop="offlineAdult" />-->
<!--      <el-table-column label="儿童" align="center" prop="offlineChildren" />-->
      <el-table-column label="停车场" align="center" prop="parkade" />
<!--      <el-table-column label="1号" align="center" prop="parkadeOne" />-->
<!--      <el-table-column label="2号" align="center" prop="parkadeTwo" />-->
<!--      <el-table-column label="3号" align="center" prop="parkadeThree" />-->
      <el-table-column label="二消营收" align="center" prop="secondRevenue" />
<!--      <el-table-column label="朐茶" align="center" prop="sr1" />-->
<!--      <el-table-column label="五谷园" align="center" prop="sr2" />-->
<!--      <el-table-column label="讲解" align="center" prop="sr3" />-->
<!--      <el-table-column label="祈福牌自助" align="center" prop="sr4" />-->
<!--      <el-table-column label="小吃车" align="center" prop="sr5" />-->
<!--      <el-table-column label="研学团建" align="center" prop="sr6" />-->
<!--      <el-table-column label="草地业态" align="center" prop="sr7" />-->
<!--      <el-table-column label="场地租赁" align="center" prop="sr8" />-->
<!--      <el-table-column label="活动集市" align="center" prop="sr9" />-->
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime)}}</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="更新时间" align="center" prop="updateTime" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.updateTime)}}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['kws:data:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['kws:data:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      :page-sizes="queryParams.pageSizes"
      @pagination="getList"
    />

    <!-- 添加或修改数据统计对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body :close-on-click-modal="false" :close-on-press-escape="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="日期" prop="rq">
              <el-date-picker clearable
                              v-model="form.rq"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="请选择日期"
                              :clearable="false"
                              :editable="false">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="天气" prop="tq">
              <el-input v-model="form.tq" placeholder="请输入天气" :maxlength="2"  show-word-limit clearable/>
            </el-form-item>
          </el-col>
          <el-col :span="6">

          </el-col>
          <el-col :span="6">
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="6">
            <el-form-item label="游客量" prop="tourists">
              <el-input v-model="form.tourists" placeholder="请输入游客量"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="刷卡" prop="swipe">
              <el-input v-model="form.swipe" placeholder="请输入刷卡" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="买票" prop="buyTickets">
              <el-input v-model="form.buyTickets" placeholder="请输入买票" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="免票" prop="freeTicket">
              <el-input v-model="form.freeTicket" placeholder="请输入免票" :value="fixFreeTicket" disabled="true"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="6">
            <el-form-item label="综合营收" prop="multiplePurpose" >
              <el-input v-model="form.multiplePurpose" placeholder="自动计算" disabled="true" :value="fixMultiplePurpose"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="门票" prop="gateMoney">
              <el-input v-model="form.gateMoney" placeholder="自动计算" disabled="true" :value="fixGateMoney"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="停车场" prop="parkade">
              <el-input v-model="form.parkade" placeholder="自动计算" disabled="true" :value="fixParkade"/>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="二消营收" prop="secondRevenue">
              <el-input v-model="form.secondRevenue" placeholder="自动计算" disabled="true" :value="fixSecondRevenue"/>
            </el-form-item>
          </el-col>
        </el-row>

        <el-divider content-position="left">
          <span style="font-size: 15px; color: #409EFF">门票</span>
        </el-divider>

        <el-row>
          <el-col :span="4">
            <el-form-item label="线上" prop="online">
              <el-input v-model="form.online" placeholder="自动计算"  disabled="true" :value="fixOnline"/>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="成人" prop="onlineAdult">
              <el-input v-model="form.onlineAdult" placeholder="请输入成人" />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="儿童" prop="onlineChildren">
              <el-input v-model="form.onlineChildren" placeholder="请输入儿童" />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="双人" prop="onlineDouble">
              <el-input v-model="form.onlineDouble" placeholder="请输入双人" />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="一大一小" prop="onlineBigSmall">
              <el-input v-model="form.onlineBigSmall" placeholder="请输入一大一小" />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="两大一小" prop="onlineTwoBigSmall">
              <el-input v-model="form.onlineTwoBigSmall" placeholder="请输入两大一小" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col  :span="4">
            <el-form-item label="线下" prop="offline">
              <el-input v-model="form.offline" placeholder="自动计算" disabled="true" :value="fixOffline"/>
            </el-form-item>
          </el-col>
          <el-col  :span="4">
            <el-form-item label="成人" prop="offlineAdult">
              <el-input v-model="form.offlineAdult" placeholder="请输入成人" />
            </el-form-item>
          </el-col>
          <el-col  :span="4">
            <el-form-item label="儿童" prop="offlineChildren">
              <el-input v-model="form.offlineChildren" placeholder="请输入儿童" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-divider content-position="left">
          <span style="font-size: 15px; color: #409EFF">停车场</span>
        </el-divider>
        <el-row>
          <el-col  :span="8">
            <el-form-item label="1号" prop="parkadeOne">
              <el-input v-model="form.parkadeOne" placeholder="请输入1号" />
            </el-form-item>
          </el-col>
          <el-col  :span="8">
            <el-form-item label="2号" prop="parkadeTwo">
              <el-input v-model="form.parkadeTwo" placeholder="请输入2号" />
            </el-form-item>
          </el-col>
          <el-col  :span="8">
            <el-form-item label="3号" prop="parkadeThree">
              <el-input v-model="form.parkadeThree" placeholder="请输入3号" />
            </el-form-item>

          </el-col>
        </el-row>

        <el-divider content-position="left" >
          <span style="font-size: 15px; color: #409EFF">二消营收</span>
        </el-divider>

        <el-row>
          <el-col  :span="8">
            <el-form-item label="朐茶" prop="sr1">
              <el-input v-model="form.sr1" placeholder="请输入朐茶" />
            </el-form-item>
          </el-col>
          <el-col  :span="8">
            <el-form-item label="五谷园" prop="sr2">
              <el-input v-model="form.sr2" placeholder="请输入五谷园" />
            </el-form-item>
          </el-col>
          <el-col  :span="8">
            <el-form-item label="讲解" prop="sr3">
              <el-input v-model="form.sr3" placeholder="请输入讲解" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col  :span="8">
            <el-form-item label="祈福牌自助" prop="sr4">
              <el-input v-model="form.sr4" placeholder="请输入祈福牌自助" />
            </el-form-item>
          </el-col>
          <el-col  :span="8">
            <el-form-item label="小吃车" prop="sr5">
              <el-input v-model="form.sr5" placeholder="请输入小吃车" />
            </el-form-item>
          </el-col>
          <el-col  :span="8">
            <el-form-item label="研学团建" prop="sr6">
              <el-input v-model="form.sr6" placeholder="请输入研学团建" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col  :span="8">
            <el-form-item label="草地业态" prop="sr7">
              <el-input v-model="form.sr7" placeholder="请输入草地业态" />
            </el-form-item>
          </el-col>
          <el-col  :span="8">
            <el-form-item label="场地租赁" prop="sr8">
              <el-input v-model="form.sr8" placeholder="请输入场地租赁" />
            </el-form-item>
          </el-col>
          <el-col  :span="8">
            <el-form-item label="活动集市" prop="sr9">
              <el-input v-model="form.sr9" placeholder="请输入活动集市" />
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listData, getData, delData, addData, updateData } from "@/api/kws/data";
import {strToNumber} from "@/utils/wfcTool"
export default {
  name: "Data",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 数据统计表格数据
      dataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 31,
        pageSizes: [31, 50],
        rq: null,
        tourists: null,
        swipe: null,
        buyTickets: null,
        freeTicket: null,
        multiplePurpose: null,
        gateMoney: null,
        online: null,
        onlineAdult: null,
        onlineChildren: null,
        onlineDouble: null,
        onlineBigSmall: null,
        onlineTwoBigSmall: null,
        offline: null,
        offlineAdult: null,
        offlineChildren: null,
        parkade: null,
        parkadeOne: null,
        parkadeTwo: null,
        parkadeThree: null,
        secondRevenue: null,
        sr1: null,
        sr2: null,
        sr3: null,
        sr4: null,
        sr5: null,
        sr6: null,
        sr7: null,
        sr8: null,
        sr9: null,
        deptId: null,
        userId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        rq: [
          { required: true, message: "日期不能为空", trigger: "blur" }
        ],
      }
    };
  },
  computed: {
    //游客量= 刷卡+买票+免票
    fixFreeTicket() {
      this.form.freeTicket = strToNumber(this.form.tourists) - strToNumber(this.form.swipe) - strToNumber(this.form.buyTickets);
    },
    //线上总金额
    fixOnline() {
      this.form.online = strToNumber(this.form.onlineAdult) + strToNumber(this.form.onlineChildren) + strToNumber(this.form.onlineDouble)
        + strToNumber(this.form.onlineBigSmall) + strToNumber(this.form.onlineTwoBigSmall);
    },
    //线下总金额
    fixOffline() {
      this.form.offline = strToNumber(this.form.offlineAdult) + strToNumber(this.form.offlineChildren);
    },
    //门票总额
    fixGateMoney() {
      this.form.gateMoney = strToNumber(this.form.online) + strToNumber(this.form.offline);
    },
    // 停车场
    fixParkade(){
      this.form.parkade = strToNumber(this.form.parkadeOne) + strToNumber(this.form.parkadeTwo)+ strToNumber(this.form.parkadeThree);
    },
    // 二消营收
    fixSecondRevenue(){
      this.form.secondRevenue =
        strToNumber(this.form.sr1) + strToNumber(this.form.sr2)+ strToNumber(this.form.sr3)
      +strToNumber(this.form.sr4) + strToNumber(this.form.sr5)+ strToNumber(this.form.sr6)
      +strToNumber(this.form.sr7) + strToNumber(this.form.sr8)+ strToNumber(this.form.sr9);
    },
    //综合营收
    fixMultiplePurpose(){
      this.form.multiplePurpose =
        strToNumber(this.form.gateMoney) + strToNumber(this.form.parkade)+ strToNumber(this.form.secondRevenue);
    }
  },

  created() {
    this.getList();
  },
  methods: {
    /** 查询数据统计列表 */
    getList() {
      this.loading = true;
      listData(this.queryParams).then(response => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        rq: null,
        tq: null,
        tourists: null,
        swipe: null,
        buyTickets: null,
        freeTicket: null,
        multiplePurpose: null,
        gateMoney: null,
        online: null,
        onlineAdult: null,
        onlineChildren: null,
        onlineDouble: null,
        onlineBigSmall: null,
        onlineTwoBigSmall: null,
        offline: null,
        offlineAdult: null,
        offlineChildren: null,
        parkade: null,
        parkadeOne: null,
        parkadeTwo: null,
        parkadeThree: null,
        secondRevenue: null,
        sr1: null,
        sr2: null,
        sr3: null,
        sr4: null,
        sr5: null,
        sr6: null,
        sr7: null,
        sr8: null,
        sr9: null,
        deptId: null,
        userId: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加数据";
      this.form.rq=new Date();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getData(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改数据";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateData(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addData(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除数据统计编号为"' + ids + '"的数据项？').then(function() {
        return delData(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('kws/data/export', {
        ...this.queryParams
      }, `data_${new Date().getTime()}.xlsx`)
    },
    /** 字符转换数子 */
    strToNumber(value) {
      let num1 = Number(value);
      if(!isNaN(num1)){
        return num1;
      }else{
        return 0;
      }
    }
  }
};
</script>
<style>
el-divider{

}
</style>
